import React from 'react';
import { connect } from 'dva';
import { List, ListView, Icon } from 'antd-mobile';
import Container from '../components/Base/Container';


const Item = List.Item;
const Brief = Item.Brief;

const data = [
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',
  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',
  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',
  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',
  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
  {
    img: <Icon type={require('../svg/user.svg')} />,
    name: '张一铭',
    tel: '13666453456',
    type: '普通会员',

  },
];
const index = data.length - 1;
let pageIndex = 0;

class P extends React.Component {
  constructor(props) {
    super(props);
    const dataSource = new ListView.DataSource({
      rowHasChanged: (row1, row2) => row1 !== row2,
    });

    this.initData = Array.from(data);
    this.state = {
      dataSource: dataSource.cloneWithRows(this.initData),
      refreshing: false,
      isLoading: false,
      hasMore: true,
    };
  }
  renderRow = (rowData) => {
    return (
      <Item
        extra="2016-01-01" align="top"
      >
        纸尿裤 <Brief><span>品牌：帮宝适</span> <span>规格：S</span> <span>数量：2</span> </Brief>
      </Item>
    );
  };
  onEndReached = (event) => {
    if (this.state.isLoading && !this.state.hasMore) {
      return;
    }
    console.log('reach end', event);
    this.setState({ isLoading: true });
    setTimeout(() => {
      pageIndex += 1;
      this.initData = [...this.initData, ...data];
      this.setState({
        dataSource: this.state.dataSource.cloneWithRows(this.initData),
        isLoading: false,
      });
      if (pageIndex > 1) {
        this.setState({
          hasMore: false,
        });
      }
    }, 1000);
  };
  render() {
    return (
      <Container title="消费记录">
        <ListView
          renderHeader={() => '共 200 条'}
          renderRow={this.renderRow}
          dataSource={this.state.dataSource}
          renderFooter={() => <div style={{ padding: 30, textAlign: 'center' }}>
            {this.state.isLoading ? '加载中...' : this.state.hasMore ? '下一页' : '全部加载完毕'}
          </div>}
          pageSize={20}
          initialListSize={20}
          scrollRenderAheadDistance={500}
          scrollEventThrottle={20}
          useBodyScroll
        />
      </Container>
    );
  }
}
export default connect()(P);
